#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年2月17日

@author: Administrator
'''

from scrapy.utils.project import get_project_settings
from celery.task import task
from django.db import connection, transaction, connections
from common.decorators.celery import task_exception_handler
from django.core import mail
from scrapy.mail import MailSender

@task
@task_exception_handler
def mail_admins(subject, message, fail_silently=False, connection=None,
                html_message=None):
    '''
    '''
    mail.mail_admins(subject, message, fail_silently, connection, html_message)



@task
@task_exception_handler
def stats_mail_send(recipients, spider_name, body):
    """
            异步爬虫异常邮件发送
    """
    scrapy_settings = get_project_settings()
    email = MailSender.from_settings(scrapy_settings)
    email.send(to=recipients, subject=spider_name, body=body)
